﻿/**
<code>
  <author name="Zealic" email="zealic(at)gmail.com" type="Creator"/>
</code>
**/
using System;
using System.Collections.Generic;


namespace Zealib.Template
{
    public class DictionaryVariableSource : IVariableSource
    {
        private IDictionary<string, string> _Dictionary;

        public DictionaryVariableSource()
        {
            _Dictionary = new Dictionary<string, string>();
        }

        public DictionaryVariableSource(IDictionary<string, string> dictionary)
        {
            if(dictionary == null)throw new ArgumentNullException("dictionary");
            _Dictionary = new Dictionary<string, string>(dictionary);
        }


        public IDictionary<string, string> Dictionary
        {
            get { return _Dictionary; }
            set { _Dictionary = value; }
        }

        public virtual string Resolve(string expression)
        {
            if (expression == null) throw new ArgumentNullException("expression");
            return Dictionary[expression];
        }
    }
}
